//package cn.yj.syslog.event;
//
//import cn.yj.commons.utils.ServletUtils;
//import cn.yj.entity.R;
//import cn.yj.syslog.common.DefaultRecords;
//import cn.yj.tools.event.ExceptionEvent;
//import com.alibaba.fastjson.JSON;
//import org.springframework.context.ApplicationListener;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//
///**
// * @author 永健
// * @since 2022-01-21 09:29
// */
//@Component
//public class ErrorResponseEventListener implements ApplicationListener<ExceptionEvent> {
//    @Override
//    public void onApplicationEvent(ExceptionEvent errorResponseEvent) {
//        int errorCode = errorResponseEvent.getErrorCode();
//        String errorMsg = errorResponseEvent.getMsg();
//        HttpServletRequest request = ServletUtils.getRequest();
//        Object logRecords = request.getAttribute("logRecords");
//        if (logRecords!=null){
//            request.removeAttribute("logRecords");
//            DefaultRecords defaultRecords = (DefaultRecords) logRecords;
//            defaultRecords.errorResult(request, JSON.toJSONString(R.build().setCode(errorCode).setMsg(errorMsg)));
//        }
//    }
//}
